Um pesquisador coletou dados sobre três variáveis psicológicas, quatro variáveis acadêmicas (resultados de testes padronizados), e o tipo de programa educacional do aluno em 600 estudantes do ensino médio.
Ele está interessado em descobrir como o conjunto de variáveis psicológicas está relacionado com as variáveis acadêmicas e o tipo de programa que o aluno está inserido.
Um médico coletou dados sobre o nível de colesterol, pressão arterial e peso. Ele também coletou dados sobre os hábitos alimentares dos pacientes (por exemplo, o quanto de carne vermelha, peixe, produtos lácteos e chocolate são consumidos por semana).
Ele quer investigar a relação entre as três medidas de saúde e hábitos alimentares de seus pacientes.
Sejam \(X_1, X_2, \cdots, X_r\) \(r\) variáveis independentes relacionadas à uma variável resposta \(Y\).
O modelo de regressão linear múltipla univariado é dado pela seguinte expressão:
\[\underbrace{Y}_{\text{resposta}} = \underbrace{\beta_0 + \beta_1X_1 + \cdots + \beta_rX_r}_{\text{média; parte estrutural}} + \underbrace{\epsilon}_{\text{erro; parte aleatória}}\]
\[Y_{i} = \beta_0 + \beta_1X_{1i} + \cdots + \beta_rX_{ri} + \epsilon_i, \hspace{0.2cm} i = 1, \cdots, n\]
Suposições
Em notação matricial, temos:
\[\underbrace{\mathbf{y}}_{n \times 1} = \underbrace{\mathbf{X}}_{n \times (r + 1)} \underbrace{\mathbf{\beta}}_{(r + 1) \times 1} + \underbrace{\mathbf{\epsilon}}_{n \times 1} \]
Suposições
\(E(\mathbf{\epsilon}) = \mathbf{0}\)
\(\text{Var}(\mathbf{\epsilon}) = \sigma^2 \mathbf{I}_n\)
\[ \mathbf{y} = \left[ \begin{matrix} y_1 \\ y_2 \\ \vdots \\ y_n \end{matrix} \right] \hspace{1cm} \mathbf{X} = \left[ \begin{matrix} 1 & X_{11} & X_{12} & \cdots & X_{1r} \\ 1 & X_{21} & X_{22} & \cdots & X_{2r} \\ \vdots & \vdots & \ddots & \vdots \\ 1 & X_{n1} & X_{n2} & \cdots & X_{nr} \end{matrix} \right] \]
\[ \mathbf{\beta} = \left[ \begin{matrix} \beta_0 \\ \beta_1 \\ \vdots \\ \beta_r \end{matrix} \right] \hspace{1cm} \mathbf{\epsilon} = \left[ \begin{matrix} \epsilon_1 \\ \epsilon_2 \\ \vdots \\ \epsilon_n \end{matrix} \right] \]
🤔
Observe que ainda não fizemos nenhuma suposição a cerca da distribuição dos erros…
Suponha que a matriz \(\mathbf{X}\) seja de posto-completo tal que suas colunas formam um conjunto L.I.
Neste caso, a matriz \(\mathbf{X}^t \mathbf{X}\) é não singular e o estimador de mínimos quadrados do vetor \(\mathbf{\beta}\) é dado por
\[\widehat{\mathbf{\beta}} = (\mathbf{X}^t \mathbf{X})^{-1}\mathbf{X}^t\mathbf{y}\]
Os valores ajustados são, então, dados por:
\[\widehat{\mathbf{y}} = \mathbf{X}\widehat{\mathbf{\beta}} = \underbrace{\mathbf{X}(\mathbf{X}^t \mathbf{X})^{-1}\mathbf{X}^t}_{\mathbf{H}}\mathbf{y} = \mathbf{H} \mathbf{y}\]
e os resíduos
\[\widehat{\mathbf{\epsilon}} = \mathbf{y} - \widehat{\mathbf{y}} = (\underbrace{\mathbf{I} - \mathbf{H}}_{\mathbf{P}} ]\mathbf{y}\]
satisfazem (somente quando houver a constante \(\beta_0\) no modelo)
\[\mathbf{X}^t\widehat{\mathbf{\epsilon}} = {\mathbf{0}} \hspace{0.5cm} e \hspace{0.5cm} \widehat{\mathbf{y}}^t\widehat{\mathbf{\epsilon}} = 0 \]
A soma de quadrados de resíduos é
\[\text{SQ Res} = \displaystyle{\sum_{i=1}^n}(y_i - \widehat{y}_i)^2 = \widehat{\mathbf{\epsilon}}^t\widehat{\mathbf{\epsilon}} = \mathbf{y}^t(\mathbf{I} - \mathbf{H})\mathbf{y} = \mathbf{y}^t\mathbf{y} - \mathbf{y}^t \mathbf{X} \widehat{\mathbf{\beta}}\]
Observe que…
\[\displaystyle{\sum_{i=1}^n} y_i^2 = \mathbf{y}^t \mathbf{y} = (\mathbf{y} - \widehat{\mathbf{y}} + \widehat{\mathbf{y}})^t (\mathbf{y} - \widehat{\mathbf{y}} + \widehat{\mathbf{y}}) = \widehat{\mathbf{y}}^t\widehat{\mathbf{y}} + \widehat{\mathbf{\epsilon}}^t \widehat{\mathbf{\epsilon}}\]
Uma vez que a primeira coluna de \(\mathbf{X}\) é \(\mathbf{1}\), a condição \(\mathbf{X}^t\widehat{\mathbf{\epsilon}} = {\mathbf{0}}\) inclui a exigência \(0 = \mathbf{1}^t\widehat{\mathbf{\epsilon}} = \displaystyle{\sum_{j=1}^n} \widehat{\mathbf{\epsilon}}_j = \displaystyle{\sum_{j=1}^n} y_j - \displaystyle{\sum_{j=1}^n} \widehat{y}_j\) ou \(\bar{y} = \bar{\widehat{y}}\). Subtraindo \(n\bar{y}^2 = n\bar{\widehat{y}}^2\) de ambos os lados, temos a decomposição básica da soma de quadrados total:
\[\text{SQ Total} = \mathbf{y}^t \mathbf{y} - n\bar{y}^2 = \widehat{\mathbf{y}}^t\widehat{\mathbf{y}} - n\bar{\widehat{y}}^2 + \widehat{\mathbf{\epsilon}}^t \widehat{\mathbf{\epsilon}}\]
De forma que, o coeficiente de determinação \(R^2\) é dado por:
\[R^2 = 1 - \dfrac{\text{SQ Res}}{\text{SQ Total}} = 1 - \dfrac{\mathbf{y}^t\mathbf{y} - \mathbf{y}^t \mathbf{X} \widehat{\mathbf{\beta}}}{\widehat{\mathbf{y}}^t\widehat{\mathbf{y}} - n\bar{\widehat{y}}^2 + \widehat{\mathbf{\epsilon}}^t \widehat{\mathbf{\epsilon}}}\]
Os dados do arquivo Exemplo_regressao_01.dat referem-se à avaliação imobiliária de 20 casas de determinado bairro em uma cidade. As variáveis envolvidas são:
dados = read.table("https://raw.githubusercontent.com/tiagomartin/est022/refs/heads/main/dados/Exemplo_regressao_01.dat", header = TRUE)
dados %>% str()'data.frame': 20 obs. of 3 variables:
$ X1: num 15.3 15.2 16.2 14.3 14.6 ...
$ X2: num 57.3 63.8 65.4 57 63.8 63.2 60.2 57.7 56.4 55.6 ...
$ Y : num 74.8 74 72.9 70 74.9 76 72 73.5 74.5 73.5 ...
[,1]
[1,] 0.9117402
[2,] 0.1078291
[3,] -3.8305847
[4,] -1.2929930
[5,] 2.6675008
[6,] -3.4763318
Call:
lm(formula = Y ~ X1 + X2, data = dados)
Residuals:
Min 1Q Median 3Q Max
-5.5894 -1.5411 -0.0718 1.3507 6.4605
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 30.96657 7.88221 3.929 0.00108 **
X1 2.63440 0.78560 3.353 0.00377 **
X2 0.04518 0.28518 0.158 0.87598
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.473 on 17 degrees of freedom
Multiple R-squared: 0.8344, Adjusted R-squared: 0.8149
F-statistic: 42.83 on 2 and 17 DF, p-value: 2.302e-07
Suponha agora, que a variável resposta é p-variada \(\mathbf{Y}\) e que \(X_1, X_2, \cdots, X_r\) representam as variáveis independentes:
\[Y_1 = \beta_{01} + \beta_{11}X_1 + \cdots + \beta_{r1}X_r + \epsilon_1\]
\[Y_2 = \beta_{02} + \beta_{12}X_1 + \cdots + \beta_{r2}X_r + \epsilon_2\]
\[\vdots \hspace{4cm} \vdots \hspace{4cm} \vdots\]
\[Y_p = \beta_{0p} + \beta_{1p}X_1 + \cdots + \beta_{rp}X_r + \epsilon_p\]
👉 Portanto, os erros associados a diferentes componentes do vetor resposta podem ser correlacionados.
Notação Matricial
\[\underbrace{\mathbf{Y}}_{n \times p} = \underbrace{\mathbf{X}}_{n \times (r + 1)} \underbrace{\mathcal{B}}_{(r + 1) \times p} + \underbrace{\mathbf{\epsilon}}_{n \times p} \]
\[ \mathbf{Y} = \left[ \begin{matrix} Y_{11} & Y_{12} & \cdots & Y_{1p} \\ Y_{21} & Y_{22} & \cdots & Y_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ Y_{n1} & Y_{n2} & \cdots & Y_{np} \end{matrix} \right] = \left[\mathbf{Y}_{(1)} | \mathbf{Y}_{(2)} | \cdots | \mathbf{Y}_{(p)} \right] \]
\[ \mathbf{X}_{n \times (r + 1)} = \left[ \begin{matrix} 1 & X_{11} & X_{12} & \cdots & X_{1r} \\ 1 & X_{21} & X_{22} & \cdots & X_{2r} \\ \vdots & \vdots & \ddots & \vdots \\ 1 & X_{n1} & X_{n2} & \cdots & X_{nr} \end{matrix} \right] \]
\[ \mathcal{B}_{(r + 1) \times p}= \left[ \begin{matrix} \beta_{01} & \beta_{02} & \cdots &\beta_{0p} \\ \beta_{11} & \beta_{12} & \cdots & \beta_{1p} \\ \vdots & \vdots & \ddots & \vdots \\ \beta_{r1} & \beta_{r2} & \cdots & \beta_{rp} \end{matrix} \right] = \left[\mathbf{\beta}_{(1)} | \mathbf{\beta}_{(2)} | \cdots | \mathbf{\beta}_{(p)} \right] \]
\[ \mathbf{\epsilon} = \left[ \begin{matrix} \epsilon_{11} & \epsilon_{12} & \cdots & \epsilon_{1p} \\ \epsilon_{21} & \epsilon_{22} & \cdots & \epsilon_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ \epsilon_{n1} & \epsilon_{n2} & \cdots & \epsilon_{np} \end{matrix} \right] = \left[\mathbf{\epsilon}_{(1)} | \mathbf{\epsilon}_{(2)} | \cdots | \mathbf{\epsilon}_{(p)} \right] \]
\[E(\mathbf{\epsilon}_{(i)}) = \mathbf{0}, \text{Cov}(\mathbf{\epsilon}_{(i)}, \mathbf{\epsilon}_{(k)}) = \sigma_{ik} \mathbf{I}_n \hspace{0.5cm} i,k = 1, 2, \cdots, p\]
🤔
\(\mathcal{B}\) e \(\mathbf{\Sigma}\) são desconhecidos…
Observe que a i-ésima coluna da matriz resposta segue o modelo linear univariado dado por:
\[\mathbf{Y}_{(i)} = \mathbf{X} \mathbf{\beta}_{(i)} + \mathbf{\epsilon}_{(i)}, \hspace{0.5cm} i = 1, 2, \cdots, p\]
com \(\text{Cov}(\mathbf{\epsilon}_{(i)}) = \sigma_{ii} \mathbf{I}_n\).
De acordo com o caso univariado, o estimador de mínimos quadrados para o vetor \(\mathbf{\beta}\):
\[\widehat{\mathbf{\beta}}_{(i)} = (\mathbf{X}^t \mathbf{X})^{-1}\mathbf{X}^t \mathbf{Y}_{(i)}, \hspace{0.5cm} i = 1, 2, \cdots, p\]
Uma vez que \(\mathcal{B} = \left[\mathbf{\beta}_{(1)} | \mathbf{\beta}_{(2)} | \cdots | \mathbf{\beta}_{(p)} \right]\), temos
\[\widehat{\mathcal{B}} = \left[\widehat{\mathbf{\beta}}_{(1)} | \widehat{\mathbf{\beta}}_{(2)} | \cdots | \widehat{\mathbf{\beta}}_{(p)} \right] = (\mathbf{X}^t \mathbf{X})^{-1} \mathbf{X}^t \left[\mathbf{Y}_{(1)} | \mathbf{Y}_{(2)} | \cdots | \mathbf{Y}_{(p)} \right]\]
ou,
\[\widehat{\mathcal{B}} = (\mathbf{X}^t \mathbf{X})^{-1} \mathbf{X}^t \mathbf{Y}\]
é o estimador de mínimos quadrados da matriz \(\mathcal{B}\)
\[\text{SQP Res} = \mathbf{\epsilon}^t\mathbf{\epsilon} = (\mathbf{Y} - \mathbf{X} \widehat{\mathcal{B}})^t(\mathbf{Y} - \mathbf{X} \widehat{\mathcal{B}})\]
\[\widehat{\mathbf{Y}} = \mathbf{X} \widehat{\mathcal{B}} = \mathbf{X}(\mathbf{X}^t \mathbf{X})^{-1} \mathbf{X}^t \mathbf{Y}\]
\[\widehat{\mathbf{\epsilon}} = (\mathbf{Y} - \widehat{\mathbf{Y}}) = (\mathbf{Y} - \mathbf{X}\widehat{\mathcal{B}}) = [\mathbf{I} - \mathbf{X}( \mathbf{X}^t \mathbf{X})^{-1} \mathbf{X}^t] \mathbf{Y}\]
Condições de ortogonalidade…
\[\mathbf{X}^t \widehat{\mathbf{\epsilon}} = \mathbf{X}^t[\mathbf{I} - \mathbf{X}(\mathbf{X}^t\mathbf{X})^{-1}\mathbf{X}^t] \mathbf{Y} = \mathbf{0}\]
\[ \widehat{\mathbf{Y}}^t \widehat{\mathbf{\epsilon}} = \widehat{\mathcal{B}}^t \mathbf{X}^t[\mathbf{I} - \mathbf{X}(\mathbf{X}^t\mathbf{X})^{-1}\mathbf{X}^t] \mathbf{Y} = \mathbf{0}\]
Uma vez que \(\mathbf{Y} = \widehat{\mathbf{Y}} + \widehat{\mathbf{\epsilon}}\),
\[\mathbf{Y}^t\mathbf{Y} = (\widehat{\mathbf{Y}} + \widehat{\mathbf{\epsilon}})^t(\widehat{\mathbf{Y}} + \widehat{\mathbf{\epsilon}}) = \widehat{\mathbf{Y}}^t\widehat{\mathbf{Y}} + \widehat{\mathbf{\epsilon}}^t\widehat{\mathbf{\epsilon}}^t + \mathbf{0} + \mathbf{0}^t\]
ou,
\[\underbrace{{\mathbf{Y}}^t{\mathbf{Y}}}_{\text{SQP total}} = \underbrace{\widehat{\mathbf{Y}}^t\widehat{\mathbf{Y}}}_{\text{SQP regressão}} + \underbrace{\widehat{\mathbf{\epsilon}}^t\widehat{\mathbf{\epsilon}}^t}_{\text{SQP Res}}\]
De forma que, a soma de quadrados e produtos cruzados dos resíduos pode ser reescrita como:
\[\widehat{\mathbf{\epsilon}}^t\widehat{\mathbf{\epsilon}}^t = \mathbf{Y}^t\mathbf{Y} - \widehat{\mathbf{Y}}^t\widehat{\mathbf{Y}} = \mathbf{Y}^t\mathbf{Y} - \widehat{\mathcal{B}}^t \mathbf{X}^t\mathbf{X}\widehat{\mathcal{B}}\]
Para o estimador de mínimos quadrados \(\widehat{\mathcal{B}}\) com a matriz \(\mathbf{X}\) de posto completo, tem-se:
\[ \begin{eqnarray*} E(\widehat{\mathcal{B}}) &=& E[(\mathbf{X}^t\mathbf{X})^{-1}\mathbf{X}^t\mathbf{Y}] = (\mathbf{X}^t\mathbf{X})^{-1}\mathbf{X}^tE(\mathbf{Y}) = \\ &=& (\mathbf{X}^t\mathbf{X})^{-1}\mathbf{X}^t\mathbf{X}\mathcal{B} = \mathbf{I}\mathcal{B} = \mathcal{B} \end{eqnarray*} \]
Além disso,
\[\text{Cov}(\widehat{\mathbf{\beta}}_{(i)},\widehat{\mathbf{\beta}}_{(k)}) = \sigma_{ik}(\mathbf{X}^t\mathbf{X})^{-1}, \hspace{0.5cm} E(\widehat{\mathbf{\epsilon}}) = \mathbf{0}, \hspace{0.5cm} E \left(\displaystyle{\dfrac{\widehat{\mathbf{\epsilon}}^t \widehat{\mathbf{\epsilon}}}{n - r - 1 }} \right) = \mathbf{\Sigma} \]
\[\widehat{\mathbf{\Sigma}} = \mathbf{S} = \displaystyle{\dfrac{\widehat{\mathbf{\epsilon}}^t\widehat{\mathbf{\epsilon}}}{n - r - 1}} = \displaystyle{\dfrac{(\mathbf{Y} - \mathbf{X} \widehat{\mathcal{B}})^t(\mathbf{Y} - \mathbf{X} \widehat{\mathcal{B}})}{n - r - 1}} = \displaystyle{\dfrac{\mathbf {Y}^t\mathbf{Y} - \widehat{\mathcal{B}}^t \mathcal{X}^t\mathbf{X}\widehat{\mathcal{B}}}{n - r - 1}}\]
Os dados do arquivo Exemplo_regressao_02.dat referem-se à medidas antropométricas, sócio-econômicas e variáveis relacionadas ao nível de estresse de 50 gestantes de um determinado município, mensuradas no último trimestre de gestação.
O estresse materno foi avaliado através de quatro variáveis distintas: resultado do teste de Estado de Ansiedade (EA), resultado do teste de Traço de Ansiedade (TA), resultado do Questionário Geral de Saúde (QGS) e Escala de Percepção de Estresse (EPE).